/***************************************************************************
 *   Copyright (C) 2008 by BogDan Vatra                                    *
 *   bogdan@licentia.eu                                                    *
 *                                                                         *
 *   This program is free software: you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/

#include <QSplashScreen>
#include <QPixmap>
#include <QTranslator>
#include <QDir>

#if defined(Q_OS_WIN)
#include <QSettings>
#include <QStyleFactory>
#endif

#include <kontamabilwindow.h>

#include "baseinterface.h"
#include "kontamabilloader.h"
#include "kontapp.h"
using namespace KontAMabil;

int main(int argc, char ** argv)
{
	KontApp app(argc, argv);
	QCoreApplication::setOrganizationName("OmniData");
	QCoreApplication::setOrganizationDomain("omnidatagrup.ro");
	QCoreApplication::setApplicationName("kontAMabil");

	QDir dir;
#if defined(Q_OS_WIN)
	dir.setPath(app.applicationDirPath()+"/translations/");
#elif defined(Q_OS_MAC)
	dir.setPath(app.applicationDirPath()+"/translations/");
#else
	dir.setPath(app.applicationDirPath()+"/../share/eXaro/translations/");
#endif
	QTranslator translator;
	if (dir.exists())
		foreach (QString file, dir.entryList(QStringList()<<QString("*_%1.qm").arg(QLocale::system().name()),QDir::Readable|QDir::Files))
		{
			translator.load(file,dir.absolutePath()+"/");
			app.installTranslator(&translator);
		}

#if defined(Q_OS_WIN)
	QSettings s;
	QApplication::setStyle(QStyleFactory::create(s.value("aplicatie/numeStil","Plastique").toString()));
	QApplication::setPalette(QApplication::style()->standardPalette());
#endif
	QDir pluginsDir = QDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN32) | defined(Q_OS_MAC)
	pluginsDir.cd("kontAMabil");
	pluginsDir.cd("plugins");
#else
	pluginsDir.cdUp();
	pluginsDir.cd("lib");
	pluginsDir.cd("kontAMabil");
	pluginsDir.cd("plugins");
#endif
	QCoreApplication::addLibraryPath(pluginsDir.absolutePath());

	QPixmap pixmap(":/images/splash.png");
	QSplashScreen splash(pixmap);
	splash.show();
	kontAMabil()->loadPlugins(&splash);
	if (!kontAMabil()->basePlugins().size())
		qFatal(QWidget::tr("nu am gasit nici un modul de baza\naplicatia nu poate continua").toAscii());
	KontAMabilWindow * window=kontAMabil()->showNextBasePlugin();
	splash.finish(window);
	return app.exec();
}
